//
//  MGDeviceConfig.m
//  Express
//
//  Created by lhongl on 2025/9/28.
//  Copyright © 2025 QM. All rights reserved.
//

#import "MGDeviceConfig.h"
@interface MGDeviceConfig ()

@property (nonatomic, assign) BOOL  isIPhoneXSeries;

@property (nonatomic, assign) CGFloat  statusHeigh;

@end
@implementation MGDeviceConfig

+ (instancetype)shareMGDeviceFrame {
    static dispatch_once_t onceToken;
    static MGDeviceConfig * deviceInfo;
    dispatch_once(&onceToken, ^{
        deviceInfo = [[MGDeviceConfig alloc] init];
        [deviceInfo setDefaultValue];
    });
    return deviceInfo;
}

#pragma mark 初始化值
- (void)setDefaultValue {
    BOOL iPhoneXSeries = NO;
    if (@available(iOS 11.0, *)) {
        UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
        if (mainWindow.safeAreaInsets.bottom > 0.0) {
            iPhoneXSeries = YES;
        }
    }
    self.isIPhoneXSeries = iPhoneXSeries;
    if (@available(iOS 13.0, *)) {
        self.statusHeigh = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame.size.height;
    }else{
        self.statusHeigh = [[UIApplication sharedApplication] statusBarFrame].size.height;
    }
}

#pragma mark - 是否是IPhone X
+ (BOOL)iPhoneXSeries {
    MGDeviceConfig *device = [MGDeviceConfig shareMGDeviceFrame];
    return device.isIPhoneXSeries;
}

#pragma mark - 状态栏高
+ (CGFloat)statusBarHeight {
    MGDeviceConfig *device = [MGDeviceConfig shareMGDeviceFrame];
    return device.statusHeigh;
}

#pragma mark - 设备高
+ (CGFloat)deviceHeight {
    return [UIScreen mainScreen].bounds.size.height;
}

#pragma mark - 设备款
+ (CGFloat)deviceWith {
    return [UIScreen mainScreen].bounds.size.width;
}

#pragma mark - 导航栏高
+ (CGFloat)deviceNavBarHeight {
    return 44.f;
}

#pragma mark - 顶部安全区域
+ (CGFloat)safeAreaTopHeight {
    return [self statusBarHeight] + [self deviceNavBarHeight];
}

#pragma mark - 底部安全区域
+ (CGFloat)safeAreaBottomHeight {
    CGFloat safeAreaHeight = 0;
    if (@available(iOS 11.0, *)) {
        UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
        safeAreaHeight = window.safeAreaInsets.bottom;
    }
    return safeAreaHeight;
}

#pragma mark - tabbar高
+ (CGFloat)deviceTabbarHeight {
    return 49.f;
}

#pragma mark 系统版本号
+ (NSString *)systemVersion {
   return [UIDevice currentDevice].systemVersion;
}

#pragma mark uuid
+ (NSString *)uuid{
   return [[UIDevice currentDevice] identifierForVendor].UUIDString;
}

@end
